#!/usr/bin/env sh
#new_rep_ip=10.45.82.51
#new_rep_ip=10.45.66.240
new_rep_ip=192.168.1.180
cur_dir=$(pwd)
for dir in $(ls -F | grep /)
do
    dir=`basename $dir`
    if [ -d "$cur_dir/$dir/.git" ];then
        cd $cur_dir/$dir
        project_name=`basename $dir`
        formal=`git remote -v | grep origin | grep -vE 'origin_|fetch'| awk '{printf( "%s\n", $2)}'`

        #skip github repo
        echo $formal | grep -E "https://github.com|gitlab|gitee.com|giteei|https" > /dev/null
        if [ $? -eq 0 ]; then
            printf "%-16s skip github|gitlab|gitee repo, change nothing.\n" "$project_name"
            continue
        fi

        new_repo=git://$new_rep_ip/${project_name}.git
        #skip already same repo
        if [ "$formal"x == "$new_repo"x ];then
            printf "%-16s same with formal repo, change nothing.\n" "$project_name"
            continue
        fi

        git remote set-url origin $new_repo 
        printf "%-16s change %s to %s.\n" "$project_name" "$formal" "$new_repo"
    fi
done




